<?
/**
 * This file is part of XNAT light.
 *
 * XNAT light is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * XNAT light is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with XNAT light.  If not, see <http://www.gnu.org/licenses/>.
 */
namespace NRG\Framework\Exceptions;

/**
 * Router exception
 *
 * @package NRG\Framework\Exceptions
 */
class RouterException extends BaseException
{
    /**
     * No such controller
     * 
     * @var int
     */
    const NO_CONTROLLER = 1;

    /**
     * No such view
     *
     * @var int
     */
    const NO_VIEW = 2;

    /**
     * No such action
     * 
     * @var int
     */
    const NO_ACTION = 3;

    /**
     * Exception type
     *
     * @var int
     */
    protected $_type;

    /**
     * Route name
     *
     * @var string
     */
    protected $_name;
    
    /**
     * Constructor
     *
     * @param int $type
     * @param string name
     */
    public function __construct($type, $name)
    {
	$this->_type = $type;
	$this->_name = $name;
        $this->createMessage();
    }

    /**
     * Get exception type
     *
     * @return int
     */
    public function getType()
    {
	return $this->_type;
    }

    /**
     * Get controller or view name
     *
     * @return string
     */
    public function getName()
    {
	return $this->_name;
    }

    /**
     * Get exception message
     *
     * @return string
     */
    public function createMessage()
    {
	switch ($this->_type)
	{
	    case self::NO_CONTROLLER:
		$this->message = "No such controller: " . $this->_name;
		break;
	    case self::NO_VIEW:
		$this->message = "No such view: " . $this->_name;
		break;
	    case self::NO_ACTION:
		$this->message = "No such action " . $this->_name;
		break;
	    default:
		$this->message = "Unknown router exception";
		break;
	}

	return $this->message;
    }
}
